<?php namespace dmq;

/**
* Auth class
* The Auth includes a User object and handles data to and from it, 
* it checks the state of logged in and logged out.
* @author dmq (master@dmq.se)
*/
class Auth
{
	/**
	* function isLoggedIn checks if user is logged in by checkning if session user is set.
	* @return boolean (true | false) The visitors logged in status.
	*/
	public function isLoggedIn()
	{
		return isset( $_SESSION['user'] );
	}
	
	/**
	* function user
	* @return User The logged in user.
	*/
	public function user( $user = false )
	{
		require_once Settings::AUTH_MODEL;
		return self::isLoggedIn() ? unserialize( $_SESSION['user'] ) : null;
	}
	
	public function login( $user )
	{
		$_SESSION['user'] = serialize( $user );
	}

	public function logout()
	{
		if ( self::isLoggedIn() )
		{
			unset( $_SESSION['user'] );
			session_destroy();
		}
	}
}
